// 二叉树的中序遍历
var inorderTraversal = function (root) {
  let res = []
  function inorder(root, res) {
    if (root === null) return
    inorder(root.left, res)
    res.push(root.val)
    inorder(root.right, res)
  }
  inorder(root, res)
  return res
}

var inorderTraversal = function (root) {
  let res = []
  if (root === null) return res

  let stack = []
  let node = root
  while (stack.length || node !== null) {
    while (node !== null) {
      stack.push(node)
      node = node.left
    }
    node = stack.pop()
    res.push(node.val)
    node = node.right
  }

  return res
}
